package com.jf3q.front.controller;

import com.jf3q.common.domain.EduCourse;
import com.jf3q.common.domain.EduOrder;
import com.jf3q.common.mapper.EduCourseMapper;
import com.jf3q.common.mapper.EduOrderMapper;
import com.jf3q.common.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@RequestMapping("/eduorder")
public class OrderController {

    @Autowired
    EduCourseMapper courseMapper;
    @Autowired
    EduOrderMapper orderMapper;
    @PostMapping("/createOrder/{id}")
    public ResultVo createOrder(@PathVariable("id") String id) {
        EduCourse eduCourse = courseMapper.selectById(id);
        EduOrder eduOrder = new EduOrder();
        eduOrder.setOrderNo(UUID.randomUUID().toString().substring(0,10));
        eduOrder.setCourseId(eduCourse.getId());
        eduOrder.setCourseTitle(eduCourse.getTitle());
        eduOrder.setCourseCover(eduCourse.getCover());
        eduOrder.setMemberId("111");
        eduOrder.setStatus((byte) 0);
        eduOrder.setPayType((byte) 2);
        eduOrder.setTeacherName("张三");
        eduOrder.setIsDeleted((byte) 0);
        orderMapper.insert(eduOrder);
        return ResultVo.success("",eduOrder.getId());
    }
    @GetMapping("/getOrderInfo/{id}")
    public ResultVo getOrderInfo(@PathVariable("id") String id) {
        EduOrder eduOrder = orderMapper.selectById(id);
        return ResultVo.success("",eduOrder);
    }
}
